﻿Imports System.Data
Imports System.Data.SqlClient
Public Class SistemasDAO
    Implements ISistema

    Private connection As SqlConnection
    Public Sub New(ByVal connection As SqlConnection)
        Me.connection = connection
    End Sub


    Public Function BuscarSistemas(ByVal parId_Sistema As Integer) As Sistema Implements ISistema.BuscarSistemas
        Me.connection.Open()
        Dim sistema As New Sistema
        Try
            Dim conn As New SqlCommand("select * from SISTEMAS inner join SISTEMATELA on SIS_CODIGO = SIT_SISTEMAS where SIT_TELA = @cod_sistema", Me.connection)
            Dim dr As SqlDataReader = conn.ExecuteReader()
            If dr.Read() Then
                sistema.ID_SISTEMA = Convert.ToInt16(dr("SIS_CODIGO"))
                sistema.NOME_SISTEMA = dr("SIS_NOME").ToString()
                sistema.INATIVO = Convert.ToInt16(dr("SIS_INATIVO")) = 0
                sistema.DATA_CADASTRO = Convert.ToDateTime(dr("TEL_D_CADASTRO"))
            End If
        Catch ex As Exception

        End Try
        Me.connection.Close()

    End Function

    Public Function ListarSistemas() As System.Collections.Generic.List(Of Sistema) Implements ISistema.ListarSistemas
        Dim listaSistema As New List(Of Sistema)
        Try
            Me.connection.Open()
            Dim conn As New SqlCommand("select * FROM SISTEMAS where SIS_INATIVO is not null", Me.connection)
            Dim dr As SqlDataReader = conn.ExecuteReader()

            While dr.Read()
                Dim sistema As New Sistema
                sistema.ID_SISTEMA = Convert.ToInt16(dr("SIS_CODIGO"))
                sistema.NOME_SISTEMA = dr("SIS_NOME").ToString()
                sistema.INATIVO = Convert.ToInt16(dr("SIS_INATIVO")) = 0
                'If Not dr("TEL_D_CADASTRO") Is Nothing Then
                '    sistema.DATA_CADASTRO = Convert.ToDateTime(dr("TEL_D_CADASTRO"))
                'End If
                listaSistema.Add(sistema)
            End While
        Catch ex As Exception
        Finally
            Me.connection.Close()
        End Try
        Return listaSistema
    End Function
End Class
